package xyz.ieden.freemarker.servlet.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xyz.ieden.freemarker.entity.User;
import xyz.ieden.freemarker.mapper.UserMapper;
import xyz.ieden.freemarker.servlet.IUserServlet;

import java.util.List;

/**
 * Created by Gavin on 2017.09.09.
 */
@Service
public class UserServletImpl implements IUserServlet {

    private static final Logger LOGGER = LoggerFactory.getLogger(UserServletImpl.class);

    @Autowired(required = false)
    private UserMapper userMapper;

    @Override
    public void deleteUserById(Long userId) {
        userMapper.deleteUserById(userId);
    }

    @Override
    public User updateUser(User user) {
        userMapper.updateUser(user);
        User qryUser = userMapper.findUserById(user.getId());
        return qryUser;
    }

    @Override
    public User saveUser(User user) {
        User saveUser = userMapper.saveUser(user);
        return saveUser;
    }

    @Override
    public User getUserById(Long userId) {
        User user = userMapper.findUserById(userId);
        return user;
    }

    @Override
    public List<User> getAllUser() {
        List<User> userList = userMapper.findAllUser();
        return userList;
    }
}
